/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ErrorListDialog.java
 *
 * Created on 08 Feb 2011, 1:14:05 PM
 */
package za.co.pas.spaceandtime.view.dlg;

import java.util.List;
import java.util.ListIterator;
import javax.swing.DefaultListModel;
import za.co.pas.business.message.StatusMessageObject;

/**
 *
 * @author alabuschagne
 */
public class ErrorListDialog extends javax.swing.JDialog
{

    /** Creates new form ErrorListDialog */
    public ErrorListDialog(java.awt.Frame parent, boolean modal)
    {
        super(parent, modal);
        initComponents();
        errorList.removeAll();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        errorList = new javax.swing.JList();
        jPanel1 = new javax.swing.JPanel();
        closeButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        errorList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(errorList);

        getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jPanel1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));

        closeButton.setText("Close");
        closeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(closeButton)
                .addContainerGap(329, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(closeButton)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void closeButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_closeButtonActionPerformed
    {//GEN-HEADEREND:event_closeButtonActionPerformed
        setVisible(false);
    }//GEN-LAST:event_closeButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton closeButton;
    private javax.swing.JList errorList;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

    public void setErrors(StatusMessageObject[] list)
    {
        DefaultListModel listModel = new DefaultListModel();
        errorList.setModel(listModel);
        for(int i = 0; i < list.length; i++)
        {
            StatusMessageObject smo = list[i];
            StringBuilder st = new StringBuilder();
            switch (smo.getStatus())
            {
                case StatusMessageObject.SMO_ERROR:
                {
                    st.append("ERROR | ");
                    break;
                }
                case StatusMessageObject.SMO_WARN:
                {
                    st.append("WARNING | ");
                    break;
                }
                case StatusMessageObject.SMO_INFO:
                {
                    st.append("INFO | ");
                    break;
                }
            }
            st.append(smo.getMessage());
            listModel.addElement(st.toString());
        }
    }
}
